<template>
  <div class="">
    <el-dialog title="用户等级统计" :visible="true" width="1400px" :modal-append-to-body="false" :close-on-click-modal="false"
      @close="handleClose">
      <div style="height: 650px; overflow: scroll">
        <el-form :inline="true">
          <el-form-item label="用户名：">
            <div>{{ info.userName || info.username }}</div>
          </el-form-item>
          <el-form-item label="用户地址：" v-if="info.userAddress">
            <div>{{ info.userAddress }}</div>
          </el-form-item>
          <el-form-item label="用户邮箱：" v-if="info.emaill">
            <div>{{ info.emaill }}</div>
          </el-form-item>
        </el-form>
        <div>
          <el-row :gutter="40" class="panel-group">
            <template>
              <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
                <div class="card-panel" @click="handleSetLineChartData('messages')">
                  <div class="card-panel-icon-wrapper icon-money">
                    <svg-icon icon-class="lir" class-name="card-panel-icon" />
                  </div>
                  <div class="card-panel-description">
                    <div class="card-panel-text">
                      普通節點
                    </div>
                    <count-to :start-val="0" :end-val="Number(total['普通節點']) || 0" :duration="2000"
                      class="card-panel-num" />
                  </div>
                </div>
              </el-col>
              <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
                <div class="card-panel" @click="handleSetLineChartData('messages')">
                  <div class="card-panel-icon-wrapper icon-lan">
                    <svg-icon icon-class="lir" class-name="card-panel-icon" />
                  </div>
                  <div class="card-panel-description">
                    <div class="card-panel-text">
                      城市節點
                    </div>
                    <count-to :start-val="0" :end-val="Number(total['城市節點']) || 0" :duration="2000"
                      class="card-panel-num" />
                  </div>
                </div>
              </el-col>
              <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
                <div class="card-panel" @click="handleSetLineChartData('messages')">
                  <div class="card-panel-icon-wrapper icon-people">
                    <svg-icon icon-class="lir" class-name="card-panel-icon" />
                  </div>
                  <div class="card-panel-description">
                    <div class="card-panel-text">
                      聯盟節點
                    </div>
                    <count-to :start-val="0" :end-val="Number(total['聯盟節點']) || 0" :duration="2000"
                      class="card-panel-num" />
                  </div>
                </div>
              </el-col>
              <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
                <div class="card-panel" @click="handleSetLineChartData('messages')">
                  <div class="card-panel-icon-wrapper icon-people">
                    <svg-icon icon-class="lir" class-name="card-panel-icon" />
                  </div>
                  <div class="card-panel-description">
                    <div class="card-panel-text">
                      超級節點
                    </div>
                    <count-to :start-val="0" :end-val="Number(total['超級節點']) || 0" :duration="2000"
                      class="card-panel-num" />
                  </div>
                </div>
              </el-col>
              <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
                <div class="card-panel" @click="handleSetLineChartData('messages')">
                  <div class="card-panel-icon-wrapper icon-people">
                    <svg-icon icon-class="lir" class-name="card-panel-icon" />
                  </div>
                  <div class="card-panel-description">
                    <div class="card-panel-text">
                      金牌節點
                    </div>
                    <count-to :start-val="0" :end-val="Number(total['金牌節點']) || 0" :duration="2000"
                      class="card-panel-num" />
                  </div>
                </div>
              </el-col>
              <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
                <div class="card-panel" @click="handleSetLineChartData('messages')">
                  <div class="card-panel-icon-wrapper icon-shopping">
                    <svg-icon icon-class="lir" class-name="card-panel-icon" />
                  </div>
                  <div class="card-panel-description">
                    <div class="card-panel-text">
                      星際節點
                    </div>
                    <count-to :start-val="0" :end-val="Number(total['星際節點']) || 0" :duration="2000"
                      class="card-panel-num" />
                  </div>
                </div>
              </el-col>
            </template>
          </el-row>
        </div>
        <div>
          <!-- 条件筛选-----查询 -->
          <el-form :inline="true">
            <div style="display: flex; justify-content: space-between;">
              <div>
                <el-form-item>
                  <label>用户等级：</label>
                  <el-select v-model="userLevel" placeholder="请选择">
                    <el-option label="全部" :value="-1" />
                    <el-option v-for="item in Object.keys(UserLevelInfo)" :label="UserLevelInfo[item]" :value="item" />
                  </el-select>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="init">查询</el-button>
                </el-form-item>
              </div>
              <div />
            </div>
          </el-form>
          <el-table v-loading="listLoading" :data="tableData" border style="width: 100%">
            <el-table-column prop="userid" label="ID" width="60" align="center" />
            <el-table-column prop="userName" label="用户信息" align="center">
              <template slot-scope="{row}">
                <div>用户名：{{ row.userName }}</div>
                <div>用户地址：{{ row.userAddress }}</div>
                <div v-if="row.emaill">用户邮箱：{{ row.emaill }}</div>
              </template>
            </el-table-column>
            <el-table-column prop="strUserLevel" label="用户等级" align="center" />
            <el-table-column prop="userLevel2" label="设置用户等级" align="center">
              <template slot-scope="{row}">
                <div>{{ UserLevelInfo[row.userLevel2] || '无' }}</div>
              </template>
            </el-table-column>
            <el-table-column prop="state" label="状态" align="center">

              <template slot-scope="{row}">
                <el-tag v-if="row.state == 1">有效</el-tag>
                <el-tag v-if="row.state == 0" type="info">无效</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="ctime" label="注册时间" align="center">

              <template slot-scope="{row}">
                <div>{{ row.ctime.replace("T", " ") }}</div>
              </template>
            </el-table-column>
            <el-table-column prop="lastIp" label="登录IP" align="center" />
          </el-table>
          <div class="block" style="padding-top: 20px">
            <el-pagination background :current-page="pageIndex" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper" :total="totalCount" @size-change="(idx) => { pageSize = idx; }
      " @current-change="(idx) => { pageIndex = idx; }" />
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import CountTo from 'vue-count-to'
import { UserLevelTotal, userLower } from "@/api/users.js";
import { GetEnum } from "@/api/ctrls.js";
export default {
  name: "Name",
  components: {
    CountTo,
  },
  props: {
    info: {
      default: {},
      type: Object
    },
  },
  data() {
    return {
      total: {},
      userLevel: -1,

      // 列表
      listLoading: false, // 列表加载中
      tableData: [],
      totalCount: 0,
      pageIndex: 1,
      pageSize: 10,

      UserLevelInfo: {}, // 用户等级
    };
  },
  watch: {
    pageIndex(val) {
      console.log(val);
      this.getData();
    },
    pageSize(val) {
      console.log(val);
      this.getData();
    },
  },
  async mounted() {
    this.getLevelTotal();
    this.getData();
    this.GetEnum();
  },
  methods: {
    handleClose() {
      this.$parent.modalStatus = 0;
    },
    // ///////////////////////////////////////////////// 数据请求 ////////////////////////////////////////////////
    /** 获取主列表 */
    async getLevelTotal() {
      const { success, data } = await UserLevelTotal({
        userid: this.info.userid
      })
      if (!success) return
      this.total = data;
    },
    /** 刷新加载 */
    init() {
      this.pageIndex = 1
      this.getData()
    },
    /** 主列表 */
    async getData() {
      this.listLoading = true
      const { list, pageIndex, totalCount } = await userLower({
        userid: this.info.userid,
        userLevel: this.userLevel,
        PageIndex: this.pageIndex,
        PageSize: this.pageSize
      })
      this.listLoading = false
      if (list) {
        this.totalCount = totalCount
        this.tableData = list
      }
    },
    // 获取枚举
    async GetEnum() {
      const res = await GetEnum();
      this.UserLevelInfo = res.data['UserLevel'];
    },
  },
};
</script>

<style lang="scss" scoped></style>
<style lang="scss">
.el-table .warning-row {
  background: oldlace;
}

.page-list {
  display: grid; // 网格布局
  grid-template-columns: 1fr 1fr; //两列平分 1fr 1fr  三列平分  1fr 1fr 1fr
  // grid-template-rows: 1fr 1fr;//两行平分
  grid-gap: 20px;
  height: 80%;
}

.chart_title {
  font-size: 22px;
  font-weight: 500;
  color: #409eff;
  margin-bottom: 10px;
}

.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #1ec8ec;
      }

      .icon-message {
        background: #fd6a5c;
      }

      .icon-money {
        background: #fd3965;
      }

      .icon-shopping {
        background: #fb7e01;
      }

      .icon-lan {
        background: #409eff;
      }

      .icon-zi {
        background: #7f77ff;
      }
    }

    .icon-people {
      color: #1ec8ec;
    }

    .icon-message {
      color: #fd6a5c;
    }

    .icon-money {
      color: #fd3965;
    }

    .icon-shopping {
      color: #fb7e01;
    }

    .icon-lan {
      color: #409eff;
    }

    .icon-zi {
      color: #7f77ff;
    }

    .card-panel-icon-wrapper {
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      font-size: 60px;
    }

    .card-panel-description {
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;
      text-align: right;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width: 600px) {
  .card-panel-icon-wrapper {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>